package com.tz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by yejf on 2017/1/11.
 */
@Controller //这是一个控制器
//@RequestMapping(value = "/hello") //将URL映射到此类
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping(value = "/hehe") //将URL映射到此方法
    public String hello(HttpServletRequest req, Model model) { //参数可以自定义
        System.out.println("--- 处理 /hello/hehe 请求....");
        //获取请求参数
        String name = req.getParameter("name");
        System.out.println("接收到的请求参数name="+name);
        //
        String result = "Hello, "+name;
        // 把数据绑定到model中
        model.addAttribute("result", result);
        //返回
        return "/index.jsp";
    }
}
